<extend name="Public:base" />
<block name="content">
<volist name="info" id="m">
    <div class="row">
        <div class="col-xs-12">
            <form class="form-horizontal"  id="validation-form" method="post" onsubmit="return check()" action='{:U("Category/editfault")}'>
            <div class="form-group required">
                <label class="col-sm-2 control-label">故障名称：</label>
                <div class="col-sm-10">
                    <input  class="form-control" style="width:220px;" type="text" placeholder="" name="fault_name"  value="{$m.name}" />
                    <input type="hidden" id="category_id" name="fault_id" value="{$m.fault_id}"/>
                </div>
            </div>
            <div class="form-group required">
                <label class="col-sm-2 control-label">故障分类：</label>
                <div class="col-sm-10">
                    <select name="catype">
                        <option>请选择类型</option>
                        <volist name="category" id="v">
                            <php>if($v['category_id'] == $m['category_id']){</php>
                            <option value="{$v.category_id}" selected="selected"><php>if($v['level']==1)echo '&nbsp;|-';</php>{$v.category_name}</option>
                            <php>}else{</php>
                            <option value="{$v.category_id}"><php>if($v['level']==1)echo '&nbsp;|-';</php>{$v.category_name}</option>
                            <php>}</php>
                        </volist>
                    </select>
                </div>
            </div>
            <div class="form-group required">
                <label class="col-sm-2 control-label">排序：</label>
                <div class="col-sm-10">
                    <input  class="form-control" style="width:220px;" type="text" placeholder="" name="order" value="{$m.order}"/>
                </div>
            </div>
            <div class="form-group required">
                <label class="col-sm-2 control-label">状态：</label>
                <?php if($m['status']==1){?>
                <label><input type="radio"  name="status" value="1" onclick="" checked="checked"/>开启</label>&nbsp;&nbsp;&nbsp;&nbsp;
                <label><input type="radio" name="status" value="2" onclick="" />关闭</label>
                <?php }else{?>
                <label><input type="radio"  name="status" value="1" onclick=""/>开启</label>&nbsp;&nbsp;&nbsp;&nbsp;
                <label><input type="radio" name ="status" value="2" onclick=""  checked="checked"/>关闭</label>
                <?php }?>
            </div>
            <div class="form-group required">
                <label class="col-sm-2 control-label">类型：</label>
                <?php if($m['fault_type']==1){?>
                <label><input type="radio"  name="type" value="1" onclick="cost()" checked="checked"/>标准</label>&nbsp;&nbsp;&nbsp;&nbsp;
                <label><input type="radio" name="type" value="2" onclick="costhide()" />非标准</label>
                <?php }else{?>
                <label><input type="radio"  name="type" value="1" onclick="cost()" />标准</label>&nbsp;&nbsp;&nbsp;&nbsp;
                <label><input type="radio" name="type" value="2" onclick="costhide() " checked="checked" >非标准</label>
                <?php }?>
            </div>
            <div id="cost">
                <div class="form-group required">
                    <label class="col-sm-2 control-label">故障价格类型：</label>
                    <div class="col-sm-10">
                        <select name="wind">
                            <option value="1">顺风</option>
                        </select>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">主材钱：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" style="width:220px;" type="text" placeholder="" name="wind_material_cost" value="{$m.wind_material_cost}"/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">耗材钱：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" style="width:220px;" type="text" placeholder="" name="wind_deplete_cost" value="{$m.wind_deplete_cost}"/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">人工费：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" style="width:220px;" type="text" placeholder="" name="wind_artificial_cost" value="{$m.wind_artificial_cost}"/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">故障价格类型：</label>
                    <div class="col-sm-10">
                        <select name="standard">
                            <option value="2" readonly>标准</option>
                        </select>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">主材钱：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" style="width:220px;" type="text" placeholder="" name="standard_material_cost" value="{$m.standard_material_cost}"/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">耗材钱：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" style="width:220px;" type="text" placeholder="" name="standard_deplete_cost" value="{$m.standard_deplete_cost}"/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">人工费：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" style="width:220px;" type="text" placeholder="" name="standard_artificial_cost" value="{$m.standard_artificial_cost}"/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">故障价格类型：</label>
                    <div class="col-sm-10">
                        <select name="expert">
                            <option value="3">专修</option>
                        </select>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">主材钱：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" style="width:220px;" type="text" placeholder="" name="expert_material_cost" value="{$m.expert_material_cost}"/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">耗材钱：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" style="width:220px;" type="text" placeholder="" name="expert_deplete_cost" value="{$m.expert_deplete_cost}"/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">人工费：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" style="width:220px;" type="text" placeholder="" name="expert_artificial_cost" value="{$m.expert_artificial_cost}"/>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" style="visibility: hidden;">上传图片：</label>
                <div class="col-sm-10">
                    <input  type="submit" value="提交" class="btn btn-primary radius5 btn-sm" />
                    <a class="btn btn-primary radius5 btn-sm" href="{:U('Category/fault')}"> 返回 </a>
                </div>
            </div>
            </form>
        </div>
    </div>
</volist>
</block>
<block name="javascript">
    <script>
        $(function(){
            var radio =$("input[name='type']:checked").val();
            if(radio==2){
                costhide();
            }
        });

        function cost(){
            $('#cost').css("display","inline");
        }
        function costhide(){
            $('#cost').hide();
        }

        function check() {
            var radio = $("input[name='type']:checked").val();
            if (radio == 1) {
                var name = $('input[name=fault_name]').val();
                var order = $('input[name=order]').val();
                var select = $("select[name=catype]").val();
                var wind_material_cost = $('input[name=wind_material_cost]').val();
                var wind_deplete_cost = $('input[name=wind_deplete_cost]').val();
                var wind_artificial_cost = $('input[name=wind_artificial_cost]').val();
                var standard_material_cost = $('input[name=standard_material_cost]').val();
                var standard_deplete_cost = $('input[name=standard_deplete_cost]').val();
                var standard_artificial_cost = $('input[name=standard_artificial_cost]').val();
                var expert_material_cost = $('input[name=expert_material_cost]').val();
                var expert_deplete_cost = $('input[name=expert_deplete_cost]').val();
                var expert_artificial_cost = $('input[name=expert_artificial_cost]').val();
                if ($.trim(name) == '') {
                    $.jbox.info('故障名称不能为空！', '提示');
                    return false;
                }
                if (select == '请选择类型') {
                    $.jbox.info('请选择一个分类！', '提示');
                    return false;
                }
                if ($.trim(order) == '') {
                    $.jbox.info('排序不能为空！', '提示');
                    return false;
                }
                if (isNaN($.trim(order))) {
                    $.jbox.info('排序请输入数字！', '提示');
                    return false;
                }
                if ($.trim(wind_material_cost) == '' || $.trim(expert_material_cost) == '' || $.trim(standard_material_cost) == '') {
                    $.jbox.info('主材钱不能为空！', '提示');
                    return false;
                }
                if (isNaN($.trim(wind_material_cost)) || isNaN($.trim(expert_material_cost)) || isNaN($.trim(standard_material_cost))) {
                    $.jbox.info('主材钱请输入数字！', '提示');
                    return false;
                }
                if ($.trim(wind_deplete_cost) == '' || $.trim(expert_deplete_cost) == '' || $.trim(standard_deplete_cost) == '') {
                    $.jbox.info('耗材钱不能为空！', '提示');
                    return false;
                }
                if (isNaN($.trim(wind_deplete_cost)) || isNaN($.trim(expert_deplete_cost)) || isNaN($.trim(standard_deplete_cost))) {
                    $.jbox.info('耗材钱请输入数字！', '提示');
                    return false;
                }
                if ($.trim(wind_artificial_cost) == '' || $.trim(expert_artificial_cost) == '' || $.trim(standard_artificial_cost) == '') {
                    $.jbox.info('人工费不能为空！', '提示');
                    return false;
                }
                if (isNaN($.trim(wind_artificial_cost)) || isNaN($.trim(expert_artificial_cost)) || isNaN($.trim(standard_artificial_cost))) {
                    $.jbox.info('人工费请输入数字！', '提示');
                    return false;
                }
            }
            $('#validation-form').ajaxSubmit(function(data){
                if(data=='1'){
                    $.jbox.tip("修改成功！", 'loading');
                    window.setTimeout(function () {window.location.href="{:U('Category/fault')}"; }, 500);
                }if(data=='2') {
                    $.jbox.info('没有任何修改！', '提示');
                }
            });

            return false;
        }
    </script>
</block>


